package com.suneast.suneaststore.modules.search.adapter;

import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suneast.suneaststore.R;
import com.suneast.suneaststore.bean.search.SearchFilterItemBean;
import com.suneast.suneaststore.modules.search.event.ItemFilterCheckChangeEvent;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

public class SearchFilterItemAdapter extends BaseQuickAdapter<SearchFilterItemBean, BaseViewHolder> {

    private String title;

    public SearchFilterItemAdapter(int layoutResId, @Nullable List<SearchFilterItemBean> data, String title) {
        super(layoutResId, data);
        this.title = title;
    }

    @Override
    protected void convert(BaseViewHolder helper, final SearchFilterItemBean item) {
        CheckBox itemCb = helper.getView(R.id.cb_filter);
        itemCb.setText(item.getName());
        itemCb.setChecked(item.isCurrent());
        itemCb.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
            Log.e("test", " oncheckchange value = " + item.getValue());
            item.setCurrent(isChecked);
            EventBus.getDefault()
                    .post(new ItemFilterCheckChangeEvent(title, isChecked, item));
        });
    }

}
